package com.design.graduation.asdemo.controller;

import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.design.graduation.asdemo.R;
import com.design.graduation.asdemo.base.ActionBarActivity;
import com.design.graduation.asdemo.model.InfoEntity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by lijinyuan on 16/2/18.
 */

public class CheckDetailsActivity extends ActionBarActivity {
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.img_title_content)
    TextView imgTitleContent;
    @Bind(R.id.details_push_img)
    LinearLayout detailsPushImg;
    @Bind(R.id.shrink_img)
    ImageView shrinkImg;
    @Bind(R.id.img_title)
    RelativeLayout imgTitle;
    @Bind(R.id.details_img)
    RecyclerView detailsImg;
    @Bind(R.id.content_map_title)
    TextView contentMapTitle;
    @Bind(R.id.shrink_position)
    ImageView shrinkPosition;
    @Bind(R.id.position_title)
    RelativeLayout positionTitle;
    @Bind(R.id.content_map)
    MapView contentMap;
    @Bind(R.id.details_price_title)
    TextView detailsPriceTitle;
    @Bind(R.id.details_price)
    EditText detailsPrice;
    @Bind(R.id.details_edit_complete)
    Button detailsEditComplete;
    @Bind(R.id.details_price_re)
    RelativeLayout detailsPriceRe;
    @Bind(R.id.details_phone_title)
    TextView detailsPhoneTitle;
    @Bind(R.id.details_phone)
    EditText detailsPhone;
    @Bind(R.id.details_phone_complete)
    Button detailsPhoneComplete;
    @Bind(R.id.details_Input_phone)
    TextInputLayout detailsInputPhone;
    @Bind(R.id.details_describe_title)
    TextView detailsDescribeTitle;
    @Bind(R.id.details_describe)
    TextView detailsDescribe;
    @Bind(R.id.write_content)
    LinearLayout writeContent;
    public MapView mapView;
    public AMap aMap;
    private InfoEntity infoEntity;

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (mapView != null && outState != null) {
            mapView.onSaveInstanceState(outState);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_check_details);
        ButterKnife.bind(this);

        mapView = (MapView) findViewById(R.id.content_map);
        mapView.onCreate(savedInstanceState);
        if (aMap == null) {
            aMap = mapView.getMap();
        }
        init();
    }

    public void init() {
        infoEntity = new InfoEntity();
        setUpMap();
        setToolBar();
        initData();
    }


    public void initData() {

    }

    private void setUpMap() {
        UiSettings uiSettings = aMap.getUiSettings();
        uiSettings.setScaleControlsEnabled(false);//比例尺
        uiSettings.setMyLocationButtonEnabled(true);//定位图标
        uiSettings.setZoomControlsEnabled(false);//显示缩放
        uiSettings.setRotateGesturesEnabled(false);//手势旋转
        uiSettings.setScrollGesturesEnabled(false);//手势移动
        uiSettings.setZoomGesturesEnabled(false);//手势缩放
        uiSettings.setMyLocationButtonEnabled(false);
        uiSettings.isMyLocationButtonEnabled();
        aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);

        CameraUpdate cu = CameraUpdateFactory.zoomTo(14);//只所放到16级别 其他参数不变
        aMap.moveCamera(cu);//通过移动相机更改地图缩放级别

    }


    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        MenuItem item1 = menu.findItem(R.id.action_text);
        MenuItem item = menu.findItem(R.id.action_img);
        item.setVisible(false);
        return true;
    }

    private void setToolBar() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("房屋信息详情");
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.icon_back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_text:
                        finish();
                        break;
                }
                return true;
            }
        });

    }

}
